<?php

namespace app\api\controller;

use app\api\model\Holiday;
use app\api\model\LetterBox;
use app\api\model\Notification;
use app\common\controller\Api;
use Carbon\Carbon;
use think\Cache;
use think\Controller;
use think\Request;

/**
 * 配置
 */
class Setting extends Api
{
    protected $noNeedLogin = ["rector", "notification"];
    protected $noNeedRight = ["*"];

    /**
     * 校长信箱
     */
    public function rector()
    {
        $rector = rector();
        $this->success("请求成功", $rector);
    }

    /**
     * 信箱留言
     */
    public function message(LetterBox $letterBox)
    {
        $user_id = $this->auth->getUserId();
        $content = $this->request->post("content");
        if (empty($content)) {
            $this->error("留言内容不能为空");
        }
        $result = $letterBox->allowField(true)->save([
            "user_id" => $user_id,
            "content" => $content
        ]);
        $result ? $this->success("留言成功") : $this->error("留言失败");
    }

    /**
     * 通知
     */
    public function notification()
    {
        $notification = Notification::getByLastTime();
        $notification ? $this->success("请求成功", compact('notification')) : $this->error("暂无通知", [], 2);
    }

    /**
     * 法定节假日
     */
    public function holiday()
    {
        $holidays = Holiday::column('date');
        $this->success("请求成功", compact('holidays'));
    }


}
